<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" />
    <button id="btn">点我节流</button>
    <script>
      // 防抖
      let ipt = document.querySelector('input')
      function fangdou() {
        let t = null // 设置一个计时器
        ipt.oninput = function () {
          if (t !== null) {
            clearTimeout(t) //清除定时器
          }
          t = setTimeout(() => {
            console.log(this.value)
          }, 1000)
        }
      }
      fangdou()

      // 节流
    </script>
  </body>
</html>
